package com.qcby.util;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author haozeWang
 * @create 2021-08-23 14:06
 */
public class LoginInterceptor implements HandlerInterceptor {

    /*对未登录用户在controller中方法执行前进行请求拦截*/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object username = request.getSession().getAttribute("username");
        if(username!=null){
            return true;
        }else {
            /*请求转发*/
            request.getRequestDispatcher("/login.jsp").forward(request,response );
            return false;
        }

    }


}
